var t = getApp(), a = require("../../../api.js");

Page({
    data: {
        positive: "",
        names: "",
        phones: "",
        type: !1,
        flag: 0,
        imgList: [],
        uploadList: []
    },
    onLoad: function(t) {
        this.data.insure_no = t.id;
    },
    upFontloadFile: function() {
        var t = this;
        wx.chooseImage({
            success: function(a) {
                var n = a.tempFilePaths;
                wx.showLoading({});
                var e = t.data.imgList;
                if (e.length + n.length > 9) return wx.showToast({
                    title: "最多上传9张",
                    icon: "none"
                }), !1;
                n.forEach(function(a, n) {
                    t.upload(a), e.push(a);
                }), t.setData({
                    imgList: e
                });
            }
        });
    },
    upload: function(n) {
        var e = this;
        if (this.data.flag >= 9) return wx.showToast({
            title: "最多上传9涨照片",
            icon: "none"
        }), !1;
        wx.uploadFile({
            url: a.driver.uploadcar,
            filePath: n,
            name: "file",
            formData: {
                access_token: wx.getStorageSync("access_token"),
                _uniacid: t.siteInfo.uniacid,
                _acid: t.siteInfo.acid
            },
            success: function(t) {
                if (wx.hideLoading(), 200 == t.statusCode) {
                    var a = JSON.parse(t.data), n = e.data.uploadList;
                    n.push(a.data), e.data.uploadList = n;
                }
            }
        });
    },
    agreement_hover: function() {
        var t = this.data.type;
        t = !t, this.setData({
            type: t
        });
    },
    formSubmit: function(n) {
        var e = this, o = n.detail.value, i = o.name, s = o.phone, u = o.address, c = o.remark;
        if (!(i && s && u && c && 0 != e.data.uploadList.length)) return wx.showToast({
            title: "请完善申报表单",
            icon: "none",
            duration: 2e3
        }), !1;
        t.request({
            url: a.order.insureReport,
            method: "post",
            data: Object.assign(n.detail.value, {
                insure_no: e.data.insure_no,
                pictures: JSON.stringify(e.data.uploadList)
            }),
            success: function(t) {
                1 != t.code ? wx.showToast({
                    title: t.msg,
                    icon: "none"
                }) : (wx.showToast({
                    title: "申报成功"
                }), setTimeout(function() {
                    wx.navigateBack();
                }, 800));
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});